#ifndef myHandler_h__
#define myHandler_h__

#include "../inc/sky.h"

namespace Sky
{
	using namespace Sky;
	class myMsgMgr;
	class Msg;
	class Handler;
	
	class Handler : public TreeNode
	{
		DECL_RTTI1(Handler,TreeNode);
	public:
		typedef fastdelegate::FastDelegate2<myMsgMgr*, Msg*,MsgStatus> Delegate;
	public:
		typedef MsgStatus (Handler::*EventId)(myMsgMgr* ,Msg* );
	protected:
		DelegatorGroup<EventId,myMsgMgr* ,Msg*>  _delegators;
	public:
		
		template <typename cls>
		EventId toEvent(MsgStatus (cls::*event)(myMsgMgr*,Msg*))
		{
			return (EventId)event;
		}
		Void addHandler(EventId e,Delegate h)
		{
			xAssert(h && e);
			_delegators.addHandler(e,h);
		}
		Void delHandler(EventId e,Delegate h)
		{
			xAssert(h && e);
			_delegators.delHandler(e,h);
		}
		MsgStatus invokeDelegate(myMsgMgr* mgr,Msg* msg);
	
	};
}
#endif // myHandler_h__
